#Subset Voterfile

vf <- data.frame()

pieces <- seq(0, 20179326, 10000)

# note: the file name is the default name from NYS. If you obtain a copy of the
# file, you will need to adjust the name to the date obtained.
for(i in 1:length(pieces)){
    temp <- read_csv(file = 'data-raw/AllNYSVoters_20201116.txt', skip = pieces[i], n_max = 10000,
                     col_names = FALSE, col_types = cols(.default = "c"))
    vf <- rbind(vf, (temp %>% filter(X22 == '44')))
}

noms <- c('LASTNAME', 'FIRSTNAME', 'MIDDLENAME', 'NAMESUFFIX', 'RADDNUMBER',
          'RHALFCODE', 'RAPARTMENT', 'RPREDIRECTION', 'RSTREETNAME', 'RPOSTDIRECTION',
          'RCITY', 'RZIP5', 'RZIP4', 'MAILADD1', 'MAILADD2',
          'MAILADD3', 'MAILADD4', 'DOB', 'GENDER', 'ENROLLMENT',
          'OTHERPARTY', 'COUNTYCODE', 'ED', 'LD', 'TOWNCITY',
          'WARD', 'CD', 'SD', 'AD', 'LASTVOTEDDATE',
          'PREVYEARVOTED', 'PREVCOUNTY', 'PREVADDRESS', 'PREVNAME', 'COUNTYVRNUMBER',
          'REGDATE', 'VRSOURCE', 'IDREQUIRED', 'IDMET', 'STATUS',
          'REASONCODE', 'INACT_DATE', 'PURGE_DATE', 'SBOEID', 'VoterHistory')

names(vf) <- noms

# We can't redistribute the NYS voterfile, so it is saved in raw.
saveRDS(vf, file = 'data-raw/RC_vf.Rds')
